/*
*************************************
* PocketGTT
*************************************
This file is part of PocketGTT.

PocketGTT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PocketGTT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PocketGTT.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GTT_PREFERREDSTOPLIST_H
#define GTT_PREFERREDSTOPLIST_H

#include <QObject>
#include <QList>
#include <QFile>
#include <QDomDocument>
#include <QDomElement>
#include <QDeclarativeContext>
#include "gtt_preferredstop.h"

class GTT_PreferredStopList : public QObject
{
    Q_OBJECT


public:
    explicit GTT_PreferredStopList(QDeclarativeContext *ctx, QObject *parent = 0);

    // inser a new element a the beginning of the list or if the element olready exists
    // move it to the first position
    void addElement(const QString &number, const QString &name, const QString &street);

    // build a description of the stop
    QString getTitle(const QString &item);


    //save list to XML file used to store preferences
    int savePreferredList2XML();

    // exctract the first element in the list
    QString getFirstPreferred();

    // remove an element from the list at position i
    void removePreferred(int i);

    // get the size of the list
    int listSize();

signals:
    void onPreferredListChanged();
    
private:

    // ptr to the QML context, necessary to update the model list in QML
    QDeclarativeContext *hiddenCtx;

    // position on filesystem for preferences file
    QString myPrivateFile;

    // manage XML preferred properties
    QDomElement Stop2Node( QDomDocument *d, GTT_PreferredStop *s );

    // create QList from the XML file
    int fillList(QFile *myFile);

    // list of preferred stop has been moved private
    // access is allowed only to functions
    QList<QObject *> preferredList;

private slots:
    // updates the list model toward QML in order to see the updates also in the UI
    void informQML();

};

#endif // GTT_PREFERREDSTOPLIST_H
